package ?????????????; // ????????????????????????????????????

import javax.swing.*; // ????swing????????????????????????
import java.awt.*; // ????awt????????????????????????
import java.awt.event.ActionEvent; // ????ActionEvent????????????????
import java.awt.event.ActionListener; // ????ActionListener????????????????????

public class ActivityDialog extends JDialog { // ????ActivityDialog?????JDialog
    private JTextField nameField; // ???????????????????????
    private JTextField dateField; // ???????????????????????
    private JTextField locationField; // ??????????????????????
    private JTextField contentField; // ???????????????????????
    private JTextField organizerField; // ????????????????????????
    private JButton confirmButton; // ??????????
    private boolean confirmed; // ?????????

    public ActivityDialog(Frame parent, boolean modal) { // ????????????????????????
        super(parent, modal); // ???????????
        setTitle("???????"); // ???????????
        setResizable(false); // ???????????????
        setSize(400, 300); // ??????????
        setLocationRelativeTo(parent); // ?????????????????????

        JPanel panel = new JPanel(new GridBagLayout()); // ??????????GridBagLayout?????JPanel
        GridBagConstraints constraints = new GridBagConstraints(); // ????GridBagConstraints???????????????????
        constraints.fill = GridBagConstraints.HORIZONTAL; // ?????????????????
        constraints.insets = new Insets(10, 10, 5, 10); // ?????????????????

        // ?????????????????
        JLabel nameLabel = new JLabel("??????:"); // ????????????
        nameField = new JTextField(20); // ???????????????????20
        constraints.gridx = 0; // ????????????????0
        constraints.gridy = 0; // ?????????????????0
        panel.add(nameLabel, constraints); // ?????????????????
        constraints.gridx = 1; // ????????????????1
        constraints.gridy = 0; // ?????????????????0
        panel.add(nameField, constraints); // ????????????????????

        // ????????????????
        JLabel dateLabel = new JLabel("?????:"); // ???????????
        dateField = new JTextField(20); // ??????????????????20
        constraints.gridx = 0; // ????????????????0
        constraints.gridy = 1; // ?????????????????1
        panel.add(dateLabel, constraints); // ????????????????
        constraints.gridx = 1; // ????????????????1
        constraints.gridy = 1; // ?????????????????1
        panel.add(dateField, constraints); // ???????????????????

        // ????????????????
        JLabel locationLabel = new JLabel("?????:"); // ???????????
        locationField = new JTextField(20); // ??????????????????20
        constraints.gridx = 0; // ????????????????0
        constraints.gridy = 2; // ?????????????????2
        panel.add(locationLabel, constraints); // ????????????????
        constraints.gridx = 1; // ????????????????1
        constraints.gridy = 2; // ?????????????????2
        panel.add(locationField, constraints); // ???????????????????

        // ?????????????????
        JLabel contentLabel = new JLabel("??????:"); // ????????????
        contentField = new JTextField(20); // ???????????????????20
        constraints.gridx = 0; // ????????????????0
        constraints.gridy = 3; // ?????????????????3
        panel.add(contentLabel, constraints); // ?????????????????
        constraints.gridx = 1; // ????????????????1
        constraints.gridy = 3; // ?????????????????3
        panel.add(contentField, constraints); // ????????????????????

        // ?????????????????
        JLabel organizerLabel = new JLabel("?????:"); // ???????????
        organizerField = new JTextField(20); // ??????????????????20
        constraints.gridx = 0; // ????????????????0
        constraints.gridy = 4; // ?????????????????4
        panel.add(organizerLabel, constraints); // ????????????????
        constraints.gridx = 1; // ????????????????1
        constraints.gridy = 4; // ?????????????????4
        panel.add(organizerField, constraints); // ???????????????????

        // ?????????
        confirmButton = new JButton("???"); // ??????????
        confirmButton.addActionListener(new ActionListener() { // ?????????????????????
            @Override
            public void actionPerformed(ActionEvent e) { // ??????????????
                confirmed = true; // ??????????true
                dispose(); // ???????
            }
        });
        constraints.gridx = 0; // ????????????????0
        constraints.gridy = 5; // ?????????????????5
        constraints.gridwidth = 2; // ????????????????2
        constraints.insets = new Insets(10, 10, 10, 10); // ?????????????????
        panel.add(confirmButton, constraints); // ???????????????

        add(panel); // ??????????????
    }

    public String[] getValues() { // ????????????
        String[] values = new String[5]; // ?????????????????????????
        values[0] = nameField.getText(); // ?????????
        values[1] = dateField.getText(); // ?????????
        values[2] = locationField.getText(); // ????????
        values[3] = contentField.getText(); // ?????????
        values[4] = organizerField.getText(); // ????????
        return values; // ?????????????
    }

    public boolean isConfirmed() { // ???????????
        return confirmed; // ?????????
    }
}
